package kr.co.webmill.model;

import java.text.SimpleDateFormat;
import java.util.List;

import kr.co.webmill.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class TodoItemAdapter extends ArrayAdapter<TodoItem> {
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		//return super.getView(position, convertView, parent);
		LinearLayout todoView;
		TodoItem item = getItem(position);
		String taskString = item.getTask();
		String dateString = new SimpleDateFormat("dd/MM/yy").format(item.getCreated());
		if(convertView == null){
			todoView = new LinearLayout(getContext());
			String inflater = Context.LAYOUT_INFLATER_SERVICE;
			LayoutInflater vi;
			vi  = (LayoutInflater) getContext().getSystemService(inflater);
			vi.inflate(resource, todoView, true);
		} else {
			todoView = (LinearLayout) convertView;
		}
		TextView dateView = (TextView) todoView.findViewById(R.id.rowDate);
		TextView taskView = (TextView) todoView.findViewById(R.id.row);
		dateView.setText(dateString);
		taskView.setText(taskString);
		return todoView;
		
	}

	public TodoItemAdapter(Context context, int resource,
			List<TodoItem> objects) {
		super(context, resource, objects);
		// TODO Auto-generated constructor stub
		this.resource = resource;
	}
	protected int resource;

}
